package com.unipock.pay.vo.auth;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.wxiaoqi.security.common.util.DateUtil;

@Entity
@Table(name = "t_user")
public class User {

	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "user_id", length = 36)
	public String id;

	/**
	 * 所属公司
	 */
	@Column(name = "company_id", length = 36)
	public String companyId;

	/**
	 * 账号
	 */
	@Column(name = "account", length = 50)
	public String account;

	/**
	 * 手机号
	 */
	@Column(name = "phone", length = 50)
	public String phone;

	/**
	 * 姓名
	 */
	@Column(name = "user_name", length = 50)
	public String name;

	/**
	 * 加密后的密码
	 */
	@Column(name = "password", length = 50)
	@JsonIgnore
	public String password;

	/**
	 * 加密后加码
	 */
	@Column(name = "salt", length = 4)
	@JsonIgnore
	public String salt;

	/**
	 * 是否为管理员
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_admin")
	public Boolean admin;

	/**
	 * Email
	 */
	@Column(name = "email", length = 50)
	public String email;

	/**
	 * 所属部门
	 */
	@ManyToOne(targetEntity = Department.class, cascade = {})
	@JoinColumn(name = "department_id", foreignKey = @ForeignKey(name = "none"))
	public Department department;

	/**
	 * 最后一次登录时间
	 */
	@Column(name = "last_login_time")
	@JsonFormat(pattern = DateUtil.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date lastLoginTime;

	/**
	 * 状态：在职、离职
	 */
	@Column(name = "is_enabled")
	@org.hibernate.annotations.Type(type = "yes_no")
	public Boolean enabled;

	/**
	 * 角色列表
	 */
	@OneToMany(targetEntity = UserRole.class, cascade = { CascadeType.REMOVE })
	@JoinColumn(name = "user_id", foreignKey = @ForeignKey(name = "none"))
	public List<UserRole> userRoleList;

	/**
	 * 录入日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "added_date")
	@JsonFormat(pattern = DateUtil.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date addedDate;

	/**
	 * 角色描述
	 */
	@Column(name = "remark", length = 255)
	public String remark;
}
